const http = require("http");

/**
 * 根据不同的路径, 返回对应的页面
 */
const app = http.createServer((req, res) => {
    const { method } = req
    console.log(method);
    const { pathname } = new URL(req.url, "http://127.0.0.1")
    console.log(pathname);

    res.setHeader('content-type', "text/html;charset=utf-8")
    if(pathname === '/search' && method === 'GET') {
        // 返回 登录页面
        res.end("login页面")
    } else if (pathname === '/user' && method === 'GET') {
        // 返回 其它页面
        res.end("user页面")
    } else {
        res.end("404 not found")
    }
})

app.listen(4000, () => {
    console.log(`端口4000已经启动!`);
})